/**
 * Created with JetBrains WebStorm.
 * User: Administrator
 * Date: 13-8-29
 * Time: 下午3:34
 * Comment：BackBone验证功能实现.
 */

$(document).ready(function () {
    var Man=Backbone.Model.extend({
        initialize:function(){
            alert("Hey,you create me!");
            this.bind("change:name",function(){
                var name=this.get("name");
                alert("changeName:"+name);
            });
        },
        default:{
            name:"zhangsan",
            age:"38"
        },
        validate:function(attributes, options){
            if(attributes.name == '') {
                return "name不能为空！";
            }

            if(attributes.age <= '18'){
                return "age不能为低于18";
            }
        },
        aboutMe:function(){
            return this.get('name')+"----"+this.get("age");
        }
    });

    $("#testVal").click(function () {
       var man=new Man();

       man.on('invalid', function(model, error){
         alert(error);
       });

       man.set(
           {name:'wong',age:16},Q
           {'validate':false}
       );

    });
});
























